package com.zy.web.bean;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @program: shopping153_cloud
 * @description: 项目中的web层的响应结果类
 * @author: zy
 * @create: 2025-08-19 15:54
 */
@Data
@Builder   //构造器注解   =>   链式调用.
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> {
    private int code;  //业务状态码
    private String msg;  //响应消息
    private T data;    //响应数据


    public static ResponseResult ok(){
        return ResponseResult.builder().code(1).msg("操作成功").build();
    }
    public static ResponseResult ok(String message){
        return ResponseResult.builder().code(1).msg(message).build();
    }

    public static ResponseResult error(){
        return ResponseResult.builder().code(0).msg("操作失败").build();
    }
    public static ResponseResult error(String message){
        return ResponseResult.builder().code(0).msg(message).build();
    }


    //放入Data的问题
    public  ResponseResult<T> setData(  T t ){
        this.data=t;
        return this;
    }

    //  使用  ResponseResult rr= ResponseResult.ok().setData( 123 );
    //    ResponseResult rr= ResponseResult.error().setData( "hello" );


}
